//引入持久层函数
const { getAll3, addOne3, deleteOne3, getOne3, upDateOne3, search3, searchClassify3, getAllGoods3 } = require("../dataBase/dao/goodsDao");
//暴露服务层函数
module.exports = {
    getAll2,
    addOne2,
    deleteOne2,
    getOne2,
    upDateOne2,
    getAllGoods2
}

//获取数据
async function getAll2({ currentPage, pageSize, condition, inputInfor, classify }) {
    if (inputInfor != "") {
        const data = await search3({ currentPage, pageSize, condition, inputInfor })
        if (data.length != 0) {
            return data
        }

    } else {
        if (classify != "") {
            const data = await searchClassify3({ currentPage, pageSize, classify })
            if (data.length != 0) {
                return data
            }
        
        }else{
            const data = await getAll3({ currentPage, pageSize })
            if (data.length != 0) {
                return data
            }
        }
       
    }
    
}


//新增商品数据
async function addOne2(data) {
    const result = await addOne3(data);
    if (result) {
        return true
    } else {
        return false
    }
}

//删除数据
async function deleteOne2(data) {
    const result = await deleteOne3(data);
    if (result) {
        return true
    } else {
        return false
    }
}

//获取一个数据
async function getOne2(_id) {
    const data = await getOne3(_id);
    if (data.length != 0) {
        return data
    }
}

//修改数据
async function upDateOne2(goods) {
    const result = await upDateOne3(goods);
    if (result) {
        return true
    } else {
        return false
    }
}

//获取全部商品
async function getAllGoods2() {
    const data = await getAllGoods3()
    if (data.length != 0) {
        return data
    }
}